/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.liquidByte.trafficMustang.server.webService.base;

/**
 * Esse DTO representa o encapsulamento das exceção que possam ocorrer
 * no servidor e que necessitam ser transportados para a chamada remota
 * de serviço
 * @author Alexandre
 */
class ResultMessage {
    private static final ResultMessage SUCCESS = new ResultMessage();
    private ErrorMessage error;
    private String jsonData;
    
    private ResultMessage(ErrorMessage error) {
        this.error = error;
    }
    private ResultMessage(String jsonData) {
        this.jsonData = jsonData;
    }
    private ResultMessage() {
        
    }

    /**
     * @return the error
     */
    public ErrorMessage getError() {
        return error;
    }

    /**
     * @return the jsonData
     */
    public String getJsonData() {
        return jsonData;
    }
    
    public static ResultMessage fromException(Exception e) {
        if (e == null) {
            return null;
        } else {
            return new ResultMessage(ErrorMessage.fromException(e));
        }
    }
    public static ResultMessage success() {
        return ResultMessage.SUCCESS;
    }
    public static ResultMessage success(String jsonData) {
        if (jsonData == null || jsonData.isEmpty()) {
            return ResultMessage.success();
        } else {
            return new ResultMessage(jsonData);
        }
    }
}
